<?php session_start(); ?>

<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->

<?php
include "Employee.php";
include "EmployeeDao.php";
include "Ticket.php";
include "TicketDao.php";
include "Customer.php";
include "CustomerDao.php";
include "CustContactLog.php";
include "CustContactLogDao.php";
include "WorkDone.php";
include "WorkDoneDao.php";
include "Datasource.php";
include "ProductDetails.php";
include "ProductDetailsDao.php";
include "CustomerProductDao.php";
include "CustomerProduct.php";

$conn = new Datasource("localhost","theanykey","root","");

$ticketDao = new TicketDao();
$ticket = $ticketDao->getObject($conn, $_Get['ticketID']);


if(isset($_GET['ticketID']))
{
    $ticket = new Ticket();
    $ticketDao = new TicketDao();
    $ticket->setTicketID($_GET['ticketID']);
    $ticketDao->load($conn, $ticket);
    $employee = new Employee();
    $employee->setEmpID($ticket->getCurrentEmpAssigned());
    $employeeDao = new EmployeeDao();
    $employeeDao->load($conn, $employee);
    $customer = new Customer();
    $customerDao = new CustomerDao();
    $customer = $customerDao->getObject($conn, $ticket->getCustomerID());
    $cmplt = $ticket->getExpectCmpltDate();

    //unfortunately php doesn't have a great way of implementing it's date class
    //in c# there is a DateTime class that can handle and format most date strings
    //sigh....

     if(substr($cmplt, 2, 1) == "-" && strlen($cmplt) == 10)
    {
        $month = substr($cmplt, 0, 2);
        $day = substr($cmplt, 3, 2);
        $year = substr($cmplt, strlen($cmplt) - 4);
        if(checkdate($month, $day, $year))
        {
             $cmplt = "$month-$day-$year";
        }
        else
        {
            $cmplt = "";
        }
    }
    else if(substr($cmplt, 4, 1) == "-" && strlen($cmplt) == 10)
    {
        $year = substr($cmplt, 0, 4);
        $month = substr($cmplt, 5, 2);
        $day = substr($cmplt, strlen($cmplt) - 2);
        if(checkdate($month, $day, $year))
        {
             $cmplt = "$month-$day-$year";
        }
        else
        {
            $cmplt = "";
        }
    }
    else
    {
        $cmplt = "";
    }
}




?>

<html>
    <head>
        <title>Triumph TTS</title>
        <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
        <link href="CalendarControl.css"
              rel="stylesheet" type="text/css">
        <script src="Calendar.js"
        language="javascript"></script>
        <style type='text/css'>
            <!--
            body {
	background-color: #454343;
	margin-left: 17px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
            }
            -->
        </style>


        <script type='text/javascript' src='tabber.js'></script>
        <link rel='stylesheet' href='triumph.css' TYPE='text/css' MEDIA='screen'>


        <script type='text/javascript'>

            /* Optional: Temporarily hide the 'tabber' class so it does not 'flash'
           on the page as plain HTML. After tabber runs, the class is changed
           to 'tabberlive' and it will appear. */

            document.write('<style type='text/css'>.tabber{display:none;}<\/style>');
        </script>



        <style type="text/css">
            <!--
            .style3 {color: #FFFFFF}
            -->
        </style>

    </head>

    <body text="#FFFFFF">

       
        <CENTER>
        <form action="TicketUpdateFunc.php" method="POST" id="ticketAddForm">
          <table id='Table_01' width='1000' height='713' border='0' cellpadding='0' cellspacing='0'>
                <tr><td align="center" bgcolor='#454343'><h2><img src="images/TitleTicketUpdate.gif" alt="Ticket Update" width="514" height="67"></h2></td></tr>
                <tr><td align="center" bgcolor="#454343"><h3>
                            <?php
                            if($_GET['prevUpdate'])
                            {
                                echo $_GET['prevUpdate'] == "success"
                                ? "Ticket #: " . $_GET['ticketID'] . " successfully updated"
                                : "Update for Ticket #: " . $_GET['ticketID'] . " failed";
                            }
                            else if($_GET['prevAdd'])
                            {
                                echo "Ticket #: " . $_GET['ticketID'] . " successfully added" ;
                            }
                            ?>
                        </h3></td></tr>
                <TR bordercolor='#000000'>
                    <TD width="1000" height='2' bgcolor='#454343'></TD>
                </TR>
                <TR bordercolor='#000000'>
                    <TD height='2' bgcolor='#454343'></TD>
                </TR>

                <!--MAIN BODY TABLE ROW -->
                <TR bordercolor='#000000' bgcolor='#454343'>
                    <TD height='249'>


                        <script type='text/javascript' src='tabber.js'>
                        </script>



                        <div class='tabber'>

                            <div class='tabbertab'>
                                <h2>Ticket</h2>

                                <center>
                                    <table>
                                        <tr>
                                            <th colspan="5" align="center">Ticket</th>
                                        </tr>
                                        <tr>
                                            <td>Ticket ID</td>
                                            <td><input type="text"  maxlength="25" id="ticketidNo" name ="ticketidNo" readonly="true" value="<?php print($_GET['ticketID']); ?>"> </td>
                                            <td colspan="1" align="center">Expected Complete Date:</td>
                                            <td><input type="text" readonly="true" maxlength="25" id="cmplt" name ="cmplt" value="<?php print($cmplt); ?>"></td>
                                            <td>
                                                <img src="images/22pxCalendar.png" onClick="showCalendarControl(document.getElementById('cmplt'));" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <th colspan="5" align="center">Employee Information</th>
                                        </tr>
                                        <tr>
                                            <td align="left">Employee ID:</td>
                                            <td><input type="text"  maxlength="25" id="empid" name ="empid" readonly="true" value="<?php print($_SESSION['userID']); ?>"> </td>
                                        </tr>
                                        <tr>
                                            <td align="left">First Name:</td>
                                            <td><input type="text"  maxlength="25" id="empfirst" name ="empfirst" readonly="true" value="<?php print($employee->getFirstName()); ?>"></td>
                                            <td align="left">Last Name:</td>
                                            <td><input type="text"  maxlength="25" id="emplast" name ="emplast" readonly="true" value="<?php print($employee->getLastName()); ?>"></td>
                                        </tr>
                                        <tr>
                                            <td align="left">Login ID:</td>
                                            <td><input type="text"  maxlength="25" id="emplogin" name ="emplogin" readonly="true" value="<?php print($employee->getLoginID()); ?>"></td>
                                            <td align="left">Role:</td>
                                            <td><input type="text"  maxlength="25" id="emprole" name ="emprole" readonly="true" value="<?php print($employee->getRole()); ?>"></td>

                                        </tr>
                                        <tr>
                                            <td align="left">Is Deleted:</td>
                                            <td><input type="text"  maxlength="25" id="isdeleted" name ="isdeleted" readonly="true" value="<?php print($employee->getIsDeleted()); ?>"></td>
                                            <td></td>
                                            <td align="center"><input type="button" value="Import Employee" onClick="openEmployeeWindow();"> </td>


                                        </tr>

                                    </table>
                                </center>
                                <script type="text/javascript">
                                    function openEmployeeWindow()
                                    {
                                        window.showModalDialog('EmployeePopUp.php','','dialogWidth:1000px; dialogHeight:300px; center:yes');
                                    }

                                </script>

                            </div>

                            <div class='tabbertab'>
                                <h2>Customer Information</h2>
                                <center>
                                    <table>
                                        <tr>
                                            <th colspan="6" align="center">Customer Information</th>
                                        </tr>
                                        <tr>
                                            <td align="left">Customer ID:</td>
                                            <td><input type="text"  maxlength="25" id="id" name ="id" readonly="true" value="<?php print($customer->getCustomerID()); ?>"> </td>
                                        </tr>
                                        <tr>
                                            <td align="left">First Name:</td>
                                            <td><input type="text"  maxlength="25" id="first" name ="first" readonly="true" value="<?php print($customer->getFirstName()); ?>"></td>
                                            <td align="left">Last Name:</td>
                                            <td><input type="text"  maxlength="25" id="last" name ="last" readonly="true" value="<?php print($customer->getLastName()); ?>"></td>
                                        </tr>
                                        <tr>
                                            <td align="left">Address:</td>
                                            <td colspan="3"><input type="text" size="58" maxlength="45" id="addr" name ="addr" readonly="true" value="<?php print($customer->getAddress()); ?>"></td>
                                        </tr>
                                        <tr>
                                            <td align="left">City:</td>
                                            <td><input type="text"  maxlength="25" id="city" name ="city" readonly="true" value="<?php print($customer->getCity()); ?>"></td>
                                            <td align="left">State:</td>
                                            <td><input type="text"  maxlength="25" id="state" name ="state" readonly="true" value="<?php print($customer->getState()); ?>"></td>
                                            <td align="left">Zip:</td>
                                            <td><input type="text"  maxlength="25" id="zip" name ="zip" readonly="true" value="<?php print($customer->getZip()); ?>"> </td>
                                        </tr>
                                        <tr>
                                            <td align="left">Phone 1:</td>
                                            <td><input type="text"  maxlength="25" id="phone1" name ="phone1" readonly="true" value="<?php print($customer->getPhoneNumber1()); ?>"></td>
                                            <td align="left">Phone 2:</td>
                                            <td><input type="text"  maxlength="25" id="phone2" name ="phone2" readonly="true" value="<?php print($customer->getPhoneNumber2()); ?>"></td>
                                            <td align="left">Phone 3:</td>
                                            <td><input type="text"  maxlength="25" id="phone3" name ="phone3" readonly="true" value="<?php print($customer->getPhoneNumber3()); ?>"> </td>
                                        </tr>
                                        <tr>
                                            <td align="left">Email:</td>
                                            <td><input type="text"  maxlength="25" id="email" name ="email" readonly="true" value="<?php print($customer->getEmail()); ?>"></td>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                            <td align="center"><input type="button" value="Import Customer" onClick="openCustomerWindow();"> </td>
                                        </tr>
                                    </table>
                                </center>

                                <script type="text/javascript">
                                    function openCustomerWindow()
                                    {
                                        window.showModalDialog('CustomerPopUp.php','','dialogWidth:1100px; dialogHeight:300px; center:yes');
                                    }

                                </script>
                            </div>


                            <div class='tabbertab' dataSrc ="workDoneDiv.php">
                                <h2>Work Done</h2>
                                <center>
                                    <table id="workDoneTable">

                                        <tr>
                                            <th colspan="4" align="center">Work Done</th>
                                        </tr>
                                        <tr>
                                            <td>Employee Assigned</td>
                                            <td><input type="hidden" id="techID" name="techID" readonly='readonly' value="<?php print($_SESSION['userID']);?>"><input type='text' readonly='readonly'  size='25' name='techName' id='techName' value="<?php print($_SESSION['EMPFIRST']);?>"></td>
                                            <td>Notes</td>
                                            <td rowspan="3"> <textarea readonly='readonly' rows='3' cols='25' size='25' name='notes' id='wdNotes'></textarea></td>
                                        </tr>
                                        <tr>
                                            <td>Date</td>
                                            <td><input type='text'  size='25' name='dateDone' readonly='readonly' id='wdDateDone'></td>
                                        </tr>
                                        <tr>
                                            <td>Hours</td>
                                            <td><input type='text'  size='25' name='hours' id='wdHours' readonly='readonly'></td>
                                        </tr>

                                    </table>
                                    <br>
                                </center>
                                <center>
                                    <input type="button" value="Add Work Done" onClick="workDonePopup();" />
                                </center>

                                <?php

                                    $workDone = new WorkDone();
                                    $workDoneDao = new WorkDoneDao();

                                    $workDone->setTicketID($_GET['ticketID']);
                                    $results = $workDoneDao->searchMatching($conn, $workDone);
                                    if($results)
                                    {
                                        print("<center><p><b>Work Done History</b></p></center>");
                                        print("<center><table class='SelectTable'>");

                                        print("<thead><tr align='center'><th></th><th></th><th>Employee Assigned</th><th>Date Done</th><th>Hours</th><th>Notes</th></tr></thead>");

                                        foreach($results as $currWork)
                                        {
                                            $tempEmp = $employeeDao->getObject($conn,$currWork->getTechAssigned());
                                            print("<tr align='center'>");
                                            print("<td><input type='button' value='Edit' onclick='window.showModalDialog(\"WorkDoneEdit.php?wrkid=".$currWork->getWrkDoneID()."\", null, \"dialogHeight:300px;dialogWidth:500px;dialogLeft:300;dialogTop:200\");'>");
                                            print("<td><input type='button' value='Delete' onclick='window.showModalDialog(\"WorkDoneDelete.php?wrkid=".$currWork->getWrkDoneID()."\", null, \"dialogHeight:300px;dialogWidth:500px;dialogLeft:300;dialogTop:200\");'>");
                                            print("<td>".$tempEmp->getFirstName()."</td>");
                                            print("<td>".$currWork->getDateDone()."</td>");
                                            print("<td>".$currWork->getHrsWorkDone()."</td>");
                                            print("<td>".$currWork->getNotes()."</td></tr>");
                                        }

                                        print("</table></center>");
                                    }
                                ?>
                            </div>

                            <div class='tabbertab'>

                                <h2>Parts Used</h2>

                                <center>
                                        <span class="divHeader">
                                            <b>Products Used</b>
                                        </span>
                                        <br/>
                                            <!--<div style="width: 95%; border:solid; border-width:1; background-color: #666666;"/>-->
                                                <table align="center">

                                                <tr align="center" style="width:10%">
                                                    <td>
                                                        ID:
                                                    </td>
                                                    <td>
                                                        <input type="text" id="pid" name="pid" readonly="readonly"/>
                                                    </td>
                                                </tr>
                                                <tr align="center" style="width:10%">
                                                    <td>
                                                        Manufacturer:
                                                    </td>
                                                    <td>
                                                        <input type="text" id="Manufac" name="Manufac" readonly="readonly"/>
                                                    </td>
                                                </tr>
                                                <tr align="center" style="width:10%">
                                                    <td>
                                                        Model Number:
                                                    </td>
                                                    <td>
                                                        <input type="text" id="ModelNum" name="ModelNum" readonly="readonly"/>
                                                    </td>
                                                </tr>
                                                <tr align="center" style="width:10%">
                                                    <td>
                                                        Serial Number:
                                                    </td>
                                                    <td>
                                                        <input type="text"  id="SerialNum" name="SerialNum" readonly="readonly"/>
                                                    </td>
                                                </tr>
                                                <tr align="center" style="width:10%">
                                                    <td>
                                                        Company Price:
                                                    </td>
                                                    <td>
                                                        <input type="text" id="CompPrice" name="CompPrice" readonly="readonly"/>
                                                    </td>
                                                </tr>
                                                <tr align="center" style="width:10%">
                                                    <td>
                                                        Customer Price:
                                                    </td>
                                                    <td>
                                                        <input type="text" id="CustPrice" name="CustPrice" readonly="readonly"/>
                                                    </td>
                                                </tr>
                                                <tr align="center" style="width:10%">
                                                    <td>
                                                        Tech Notes:
                                                    </td>
                                                    <td>
                                                        <input type="text" id="TechN" name="TechN" readonly="readonly"/>
                                                    </td>
                                                </tr>
                                            </table>
                                            <input type="button" value="Add Product" onclick="window.showModalDialog('productPopup.php', 'Add Product', 'menubar=0, toolbar=0, height=180px, width=280px');" />
                                            <input type="hidden" id="hdnID" value="" name="hdnID"/>
                                    </center>
                                </br>


                                <center>
                                    <b>Previous Parts<b>
                                </center>
                                <center>
                                    <table style="width: 90%">
                                        <tr>
                                            <th></th>
                                            <th align="center">
                                                ID
                                            </th>
                                            <th align="center">
                                                Manufacturer
                                            </th>
                                            <th align="center">
                                                Model Number
                                            </th>
                                            <th align="center">
                                                Serial Number
                                            </th>
                                            <th align="center">
                                                Company Price
                                            </th>
                                            <th align="center">
                                                Customer Price
                                            </th>
                                            <th align="center">
                                                Tech Notes
                                            </th>
                                        </tr>

                            <?php


                            $tempCustProd = new CustomerProduct();
                            $tempCustProd->setTicketID($_GET['ticketID']);
                            $custProdDao = new CustomerProductDao();
                            $results = $custProdDao->searchMatching($conn, $tempCustProd);

                            $counter = 1;
                            foreach ($results as $currentRow)
                            {
                            $currentProdDetails = new ProductDetails();
                            $currentProdDetailsDao = new ProductDetailsDao();
                            $currentProdDetails = $currentProdDetailsDao->getObject($conn, $currentRow->getProductDetailsID());
                            $id = $currentRow->getCustomerProductID();
                            print("<tr align='center' id=custProdRow$counter name=rowID>");
                            print("<td>
     <input type='button' value='Delete' onclick=\"window.open('ProductDeletePopup.php?id=$id&row=custProdRow$counter',null, 'menubar=0, toolbar=0, height=400px, width=780px')\";>
            </td>");
                            $notes = $currentProdDetails->getTechNotes();
                            $shortNotes = substr($notes, 0, 25)."...";
                            print (" <td>".$currentProdDetails->getProductID()."</td>
                        <td>".$currentProdDetails->getManufacturer()."</td>
                        <td>".$currentProdDetails->getModelNo()."</td>
                        <td>".$currentProdDetails->getSerialNo()."</td>
                        <td>".$currentProdDetails->getCompanyPrice()."</td>
                        <td>".$currentProdDetails->getCustomerPrice()."</td>
                        <td><span title='$notes'>$shortNotes</span></td>

                  </tr>");
                            $counter++;
                            } ?>
                                        </table>
                                        </center>
                                        <span id="htmlWrite">
                                        </span>

                                        </div>
                            

                            <div class='tabbertab'>
                                <h2>Customer Contact Log</h2>
                            <center>
                                        <b>Customer Contact Log</b>
                                        <table>
                                            <tr>
                                                <td>
                                                    Date Contacted:
                                                </td>
                                                <td>
                                                    <input type="text" id="custContactDate" name="custContactDate" readonly="true"/>
                                                </td>
                                                <td>
                                                    <input type="button" value="Add/Edit" onClick="window.showModalDialog('CustomerContactPopup.php', null, 'dialogHeight:300px;dialogWidth:500px;dialogLeft:300;dialogTop:200');" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    Contact Notes:
                                                </td>
                                                <td colspan="2">
                                                    <textarea readonly="true" id="txtAreaCustContactNotes" name="txtAreaCustContactNotes" rows="3" cols="40"></textarea>
                                                </td>
                                            </tr>
                                        </table>
                                    </center>
                                <br/>
                                <center>
                                    <?php
                                        $custContactLog = new CustContactLog();
                                        $custContactDao = new CustContactLogDao();
                                        $custContactLog->setTicketID($_GET['ticketID']);
                                        $results = $custContactDao->searchMatching($conn, $custContactLog);
                                        if($results)
                                        {
                                            print("<center><p><b>Customer Contact History</b></p></center>");

                                            print("<center><table class='SelectTable'>");

                                            print("<thead><tr align='center'><th></th><th></th><th>Employee</th><th>Date</th><th>Contact Notes</th></tr></thead><tbody>");

                                            foreach($results as $obj)
                                            {
                                                $employee = $employeeDao->getObject($conn, $obj->getEmpID());
                                                $empFirst = $employee->getFirstName();
                                                $empLast = $employee->getLastName();
                                                $notes = $obj->getContactNotes();
                                                $date = $obj->getDateContacted();
                                                $ccID = $obj->getCntctLogID();
                                                $funct = ($obj->getEmpID() == $_SESSION['userID']) ? "Edit" : "View";
                                                print("<tr><td><input type='button' value='$funct' onclick=\"showModalDialog('CustContactPopupEdit.php?custContID=$ccID&Func=$funct','','dialogHeight:300px;dialogWidth:500px;dialogLeft:300;dialogTop:200');\" />"
                                                     . "</td><td>");
                                                 if($funct == "Edit")
                                                 {
                                                    print("<input type='button' value='Delete' onclick=\"showModalDialog('CustContactPopupDelete.php?custContID=$ccID','','dialogHeight:300px;dialogWidth:500px;dialogLeft:300;dialogTop:200');\" />");
                                                 }
                                                 print("</td><td>$empLast, $empFirst</td><td>$date</td><td>$notes</td></tr>");


                                            }
                                            print("</tbody></table>");
                                        }

                                    ?>
                                </center>
                            </div>
                        </div> </TD>
                </TR>

                <TR bordercolor='#000000'>
                    <TD  bgcolor='#454343'><div align="center">
                      <input name="submit" type="submit" value="Submit">
                    </div></TD>
                </TR>
                <TR bordercolor='#000000'>
                    <TD height='442' bgcolor='#454343'>
                        <div align="center">

                        </div>
                    </TD>
                </TR>
            </table>
            </form>
        </CENTER>
</body>

<SCRIPT>
     function checkHiddenValue()
     {
        // alert("called");
         alert(document.getElementById("wdPK1").value);
     }
     function removeLast()
     {
        table = document.getElementById("tblWorkDone");
        table.deleteRow(table.rows.length - 1);
     }
       function getBrowser()
       {
            return navigator.appName;
       }
       function workDonePopup()
       {
           if(getBrowser() == 'Microsoft Internet Explorer')
           {
               //showModalDialog does not yield a window.opener type in IE
               //stupid IE!
               window.open('WorkDonePopup.php', null, 'width=550, height=300');
           }
           else
           {
                window.showModalDialog('WorkDonePopup.php', null, 'dialogHeight:300px;dialogWidth:550px;dialogLeft:300;dialogTop:200');
           }
       }
       function editWorkDonePopup(workDoneID, rowID, editOrDelete)
       {
           if(getBrowser() == 'Microsoft Internet Explorer')
           {
               //showModalDialog does not yield a window.opener type in IE
               //stupid IE!
               window.open("EditWorkDonePopup.php?id=" + workDoneID + "&row=" + rowID + "&function=" + editOrDelete, null, 'width=500, height=300');

           }
           else
           {
                window.showModalDialog("EditWorkDonePopup.php?id=" + workDoneID + "&row=" + rowID + "&function=" + editOrDelete, null, 'dialogHeight:300px;dialogWidth:500px;dialogLeft:300;dialogTop:200');
           }
       }
</SCRIPT>
</html>
